home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / IntlTest / Sources / EditViews.h < prev    next >
Encoding:
Text File  |  1996-09-12  |  8.1 KB  |  258 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                EditViews.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Mary Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef EDITVIEWS_H
  13. #define EDITVIEWS_H
  14.  
  15. #ifndef COMMANDS_H
  16. #include "Commands.h"
  17. #endif
  18.  
  19. // ----- ODF Includes -----
  20.  
  21. #ifndef FWEDVIEW_H
  22. #include "FWEdView.h"
  23. #endif
  24.  
  25. #ifndef FWSCPTBL_H
  26. #include "FWScptbl.h"
  27. #endif
  28.  
  29. #ifndef FWPULLDM_H
  30. #include "FWPullDM.h"
  31. #endif
  32.  
  33. // ----- Macintosh Includes -----
  34.  
  35. #ifndef __TEXTEDIT__
  36. #include <TextEdit.h>
  37. #endif
  38.  
  39. #ifndef __TEXTSERVICES__
  40. #include <TextServices.h>
  41. #endif
  42.  
  43. #ifndef __TSMTE__
  44. #include <TSMTe.h>
  45. #endif
  46.  
  47. //========================================================================================
  48. // Forward Declarations
  49. //========================================================================================
  50.  
  51. class CIntlTestPart;
  52. class FW_CViewContext;
  53. class FW_CMouseEvent;
  54. class FW_CClipboardCommand;
  55. class CTypingCommand;
  56. class CTSMTypingCommand;
  57.  
  58. //========================================================================================
  59. // Constants and Globals
  60. //========================================================================================
  61.  
  62. extern FW_CFont gFontOsaka;                    // Default Japanese font
  63.  
  64. extern ODMenuID gSizeMenuID;                // the Size menu's ID
  65. extern FW_CPullDownMenu* gFontMenu;            // the current Font menu
  66. extern short gFontCount;                    // number of items in the current Font menu
  67.  
  68. extern FW_CPullDownMenu* gDefaultFontMenu;    // default Font menu (Roman fonts only)
  69. extern FW_CPullDownMenu* gJFontMenu;        // Japanese Font menu
  70.  
  71. const FW_Message kEditViewMsg = 45;            // ASCII 'E'
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // Enumeration for ASCII Character Constants - copied from MacApp
  75. //----------------------------------------------------------------------------------------
  76.  
  77. enum EAsciiControlCode {
  78.     chBackspace = 8,                    // ASCII code for Backspace character  
  79.     chClear = 27,                        // ASCII code for Clear key (aka ESC)  
  80.     chDown = 31,                        // ASCII code for down arrow  
  81.     chEnd = 4,                            // ASCII code for the End key  
  82.     chEnter = 3,                        // ASCII code for Enter character  
  83.     chEscape = 27,                        // ASCII code for Escape (aka Clear) key  
  84.     chFunction = 16,                    // ASCII code for any function key  
  85.     chFwdDelete = 127,                    // ASCII code for forward delete  
  86.     chHelp = 5,                            // ASCII code for Help key  
  87.     chHome = 1,                            // ASCII code for the Home key  
  88.     chLeft = 28,                        // ASCII code for left arrow  
  89.     chPageDown = 12,                    // ASCII code for Page Down key  
  90.     chPageUp = 11,                        // ASCII code for Page Up key  
  91.     chReturn = 13,                        // ASCII code for Return character  
  92.     chRight = 29,                        // ASCII code for right arrow  
  93.     chSpace = 32,                        // ASCII code for Space character  
  94.     chTab = 9,                            // ASCII code for Tab character  
  95.     chUp = 30                            // ASCII code for up arrow
  96. };
  97.  
  98. //========================================================================================
  99. // FW_MTSMHandler - a mixin for views that use the Text Services Manager
  100. //========================================================================================
  101. class FW_MTSMHandler
  102. {
  103.   public:
  104.     FW_DECLARE_CLASS
  105.  
  106.     FW_MTSMHandler(FW_CEditView* theView);
  107.     virtual ~FW_MTSMHandler();
  108.  
  109.     FW_Boolean CreateTSMDocument(TEHandle te);
  110.  
  111.     FW_Boolean DoActivateTSM(FW_Boolean becomingActive);
  112.     FW_Boolean DoFixTSMDocument();
  113.  
  114.     TSMDocumentID GetTSMDocument() const;
  115.     void SetTSMDocument(TSMDocumentID docId);
  116.  
  117.   private:
  118.     TSMDocumentID    fTSMDocId;
  119.     TSMTERecHandle    fTSMHandle;
  120.     FW_CEditView*    fEditView;
  121.     OSErr            fError;        // error from last TSM call
  122. };
  123.  
  124. //----------------------------------------------------------------------------------------
  125. inline TSMDocumentID FW_MTSMHandler::GetTSMDocument() const
  126. {
  127.     return fTSMDocId;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. inline void FW_MTSMHandler::SetTSMDocument(TSMDocumentID docId)
  132. {
  133.     fTSMDocId = docId;
  134. }
  135.  
  136. //========================================================================================
  137. // CMyEditView - experiment with typing Undo/Redo
  138. //========================================================================================
  139. class CMyEditView : public FW_CEditView
  140. {
  141.   public:
  142.     FW_DECLARE_CLASS
  143.     FW_DECLARE_AUTO(CMyEditView)
  144.  
  145.   public:        
  146.     CMyEditView(Environment* ev,
  147.                 FW_CSuperView* container, 
  148.                 const FW_CRect& bounds,
  149.                 ODID viewId,
  150.                 const FW_CFont& font,
  151.                 short maxChars,
  152.                 unsigned short attributes);
  153.  
  154.     CMyEditView(Environment* ev);    // default constructor
  155.     virtual ~ CMyEditView();
  156.  
  157.   public:
  158.     // ----- Events -----
  159.     virtual void         ActivateTarget(Environment* ev, FW_Boolean tabSelection);
  160.     virtual void        DeactivateTarget(Environment* ev);
  161.     virtual FW_Handled    DoAdjustMenus(Environment* ev,
  162.                                       FW_CMenuBar* menuBar, 
  163.                                       FW_Boolean hasMenuFocus,
  164.                                       FW_Boolean isRoot);
  165.     virtual FW_Handled    DoCharKey(Environment* ev, const FW_CCharKeyEvent& event);
  166.     virtual FW_Handled    DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent);
  167.     virtual FW_Handled    DoMouseDown(Environment* ev, const FW_CMouseEvent& event);
  168.  
  169.     // ----- Archiving -----
  170.     static void*        Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  171.     static void            Destroy(void* object, FW_ClassTypeConstant type);
  172.     virtual void        Flatten(Environment* ev, FW_CWritableStream& stream) const;
  173.     virtual void        InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  174.  
  175.     virtual void        PostCreateViewFromStream(Environment* ev);
  176.  
  177.     // ----- New Stuff -----
  178.     void                CommandToString(Environment* ev, ODCommandID id, FW_CString& string);
  179.     void                DoSetFont(Environment* ev, ODCommandID id, const FW_CString& fontName);
  180.     void                DoSetFontSize(Environment* ev, int fontSize);
  181.     FW_CFont            GetCurrentFont();
  182.     ODCommandID            GetCurrentFontCmd(Environment* ev);
  183.  
  184.     void                TypingCommandAboutToBeDestroyed(CTypingCommand* cmd);
  185.  
  186.   protected:
  187.     FW_CMenuBar*        GetMenuBar(Environment* ev);
  188.     ODCommandID            GetCurrentSizeCmd();
  189.  
  190.     virtual FW_CPullDownMenu* GetMyFontMenu();
  191.  
  192.     void                DoneTyping(Environment* ev);
  193.     FW_Boolean            IsArrowKey(char ch);
  194.  
  195.   private:
  196.     CTypingCommand*        NewTypingCommand(Environment* ev, char firstChar);
  197.  
  198.   protected:
  199.     CTypingCommand*        fTypingCommand;
  200.     FW_CString            fFontName;            // name of current font
  201.     ODCommandID            fFontCmd;            // current font command id
  202.     int                    fFontSize;            // current font size
  203. };
  204.  
  205. //========================================================================================
  206. // CJEditView
  207. //========================================================================================
  208. class CJEditView : public CMyEditView, public FW_MTSMHandler
  209. {
  210.   public:
  211.     FW_DECLARE_CLASS
  212.     FW_DECLARE_AUTO(CJEditView)
  213.  
  214.   public:        
  215.     CJEditView(Environment* ev,
  216.                 FW_CSuperView* container, 
  217.                 const FW_CRect& bounds,
  218.                 ODID viewId,
  219.                 const FW_CFont& font,
  220.                 short maxChars,
  221.                 unsigned short attributes);
  222.     CJEditView(Environment* ev);
  223.     virtual ~ CJEditView();
  224.  
  225.     void                InitJEditView(Environment* ev);
  226.     virtual void        PostCreateViewFromStream(Environment* ev);
  227.  
  228.   public:
  229.     virtual void         ActivateTarget(Environment* ev, FW_Boolean tabSelection);
  230.     virtual void         DeactivateTarget(Environment* ev);
  231.  
  232.     virtual FW_Handled    DoCharKey(Environment* ev, const FW_CCharKeyEvent& event);
  233.     virtual FW_Handled    DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent);
  234.  
  235.     // ----- Archiving -----
  236.     static void*        Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  237.     static void            Destroy(void* object, FW_ClassTypeConstant type);
  238.  
  239.   public:
  240.     void                AddInput(Environment* ev, CTSMInput* input);
  241.     void                DoMakeTypingCommand(Environment* ev = NULL);
  242.     FW_Boolean            IsFirstEventInSequence();
  243.  
  244.   protected:
  245.     virtual FW_CPullDownMenu* GetMyFontMenu();
  246.  
  247.   private:
  248.     CTSMTypingCommand*    NewTypingCommand(Environment* ev, CTSMInput* firstInput);
  249.     CTSMTypingCommand*    fTSMTypingCommand;
  250.  
  251.   private:
  252.     short        fMyFont;                // my font
  253.     short        fMyFontScript;            // my font's script
  254.     short        fPreviousFontScript;    // font script saved on activation, restored on deactivation
  255. };
  256.  
  257.  
  258. #endif